<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-1.8.3.min.js"></script>
</head>
<body>


    <form action="" method="post">
        用户名:<input type="text" name="username" id="username"/><br/>
        密码:<input type="text" name="passwords" id="password"/>
        <input type="button"  id="btn1" value="登录"/>
    </form>


    <script>
        $(function(){

            $("#btn1").click(function(){
                //表示整个页面加载完之后执行
                let username=$("#username").val();
                let password=$("#password").val();
                //获取按钮，并添加点击事件，发送ajax
                $.ajax({
                    url:"/user/login",
                    type:"post",
                    data:'{"username":"'+username+'","password":"'+password+'"}',
                    contentType:"application/json",
                    dataType:"json",
                    success:function(data){
                        if(data.flag==true){
                            location.href="success.html"
                        }else{
                            alert(data.message)
                        }
                    }
                })
            })
        })

    </script>
</body>
</html>